import React from "react";
import { Switch, Route, Redirect } from "react-router-dom";

const SubRoutes = (route) => {

  return route.tag === "Redirect" ? (
    <Redirect
      from={route.from}
      to={route.to}
      exact={route.exact}
      render={(props) =>   <route.component {...props} routes={route.children} />}
    ></Redirect>
  ) : (
    <Route
      path={route.path}
      exact={route.exact}
      render={(props) => <route.component {...props} routes={route.children} />}
    ></Route>
  );
};
const Routes = (props) => {
  return (
    <Switch>
      {props.routes.map((item, index) => (
        <SubRoutes key={index} {...item} />
      ))}
    </Switch>
  );
};

export default Routes;
